/////////////////////////////////////////////////////////////////////////////
// Name:        stringtable.h
// Purpose:     Manages a table of strings, e.g. alternative translations
// Author:      Julian Smart
// Modified by:
// Created:     2008-02-05
// RCS-ID:      $Id$
// Copyright:   (c) Julian Smart
// Licence:     New BSD License
/////////////////////////////////////////////////////////////////////////////

#ifndef _STRINGTABLE_H_
#define _STRINGTABLE_H_

#include "wx/wx.h"

/*!
 * wxStringTable holds an arbitrary set of strings and associated
 * translations/alternatives.
 */

class wxStringTable
{
public:
    wxStringTable() {}

    /// Add a string
    void AddString(const wxString& name, const wxString& value = wxEmptyString);

    /// Remove a string
    void RemoveString(const wxString& name);
    void RemoveString(int idx);

    /// Get string count
    size_t GetCount() const { return m_stringNames.GetCount(); }

    /// Clear the table
    void Clear() { m_stringNames.Clear(); m_stringValues.Clear(); }

    /// Just clear the values
    void ClearValues();

    /// Find a string index
    int FindString(const wxString& name) const;

    /// Get the string for the given string, or the value of name if not found or empty
    wxString GetString(const wxString& name) const;

    /// Get the string at the given index
    wxString GetString(size_t i) const;

    /// Get the string pointer at the given index
    wxString* GetStringPtr(size_t i) const;

    /// Get the string at the given index, without substituting the name for an empty string
    wxString GetStringRaw(size_t i) const;

    /// Get the name at the given index
    wxString GetName(size_t i) const;

    /// Set the name at the given index
    void SetName(size_t i, const wxString& name);

    /// Set the value at the given index
    void SetString(size_t i, const wxString& value);

    /// Set the value for the given name, adding if not found.
    void SetString(const wxString& name, const wxString& value);

    /// Get the table name
    const wxString& GetTableName() const { return m_tableName; }

    /// Set the table name
    void SetTableName(const wxString& name) { m_tableName = name; }

    /// Load from file
    bool LoadFile(const wxString& filename);

    /// Save to file
    bool SaveFile(const wxString& filename);

protected:

    wxArrayString m_stringNames;
    wxArrayString m_stringValues;

    wxString      m_tableName;
};

/*!
 * wxStringTablePanel class declaration
 */

class wxStringTablePanel: public wxScrolledWindow
{    
    DECLARE_DYNAMIC_CLASS( wxStringTablePanel )
    DECLARE_EVENT_TABLE()

public:
    /// Constructors
    wxStringTablePanel();
    wxStringTablePanel( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0 )
    {
        Create(NULL, parent, id, pos, size, style);
    }
    wxStringTablePanel( wxStringTable* table, wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0 );

    /// Creation
    bool Create( wxStringTable* table, wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0 );

    /// Destructor
    ~wxStringTablePanel();

    /// Initialises member variables
    void Init();

    /// Creates the controls and sizers
    void CreateControls();

    /// Refresh table
    void ShowTable();

    /// Rebuild and refresh table
    void RebuildTable(wxStringTable* table = NULL);

    /// Get/set table
    wxStringTable* GetTable() const { return m_table; }
    void SetTable(wxStringTable* table) { m_table = table; }

protected:

    wxStringTable* m_table;
};

#endif
    // _STRINGTABLE_H_
